﻿@using System.Configuration
@{
    ViewBag.Title = "Quản Lý Đơn Trả Muộn Sách";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
}

<div id="div-main-menu" class="left-side-bar">
    @Html.Partial("_AdminMenu")
</div>
<div id="div-main-content" class="right-side-bar">
    <h2>QUẢN LÝ ĐƠN TRẢ MUỘN SÁCH</h2>
    <div class="filtering">
        <form>
            <label>Mã mượn sách: </label><input type="text" name="borrowingID" id="borrowingID" />        
            <label>Nhân viên:</label>@Html.DropDownList("employerID", (IEnumerable<SelectListItem>)ViewBag.Employees, new { id = "empID" })
            <button type="submit" id="LoadRecordsButton">Tìm kiếm</button>
        </form>
    </div>
    <div id="LibrarySkippingContainer"></div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#LibrarySkippingContainer').jtable({
            title: 'Bảng danh sách hoãn trả sách',
            paging: true, //Enable paging
            pageSize: @ConfigurationManager.AppSettings["PageSize"],
            sorting: true, //Enable sorting
            defaultSorting: 'BorrowingID ASC',
            //openChildAsAccordion: true, //Enable this line to show child tabes as accordion style
            actions: {
                listAction: '@Url.Action("GetSkippingList", "Skipping")',
                deleteAction: '@Url.Action("DeleteSkipping","Skipping")',
                updateAction: '@Url.Action("UpdateSkipping", "Skipping")',
                createAction: '@Url.Action("AddSkipping", "Skipping")'
            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                SkippingDetailList:{
                    title: ' ',
                    sorting: false,
                    edit: false,
                    create: false,
                    listClass: ' ',
                    display: function (SkippingDetailData) {
                        //Create an image that will be used to open child table
                        var $img = $('<img class="child-opener-image" src="/Content/images/Misc/note.png" title="Skipping Detail List" />');
                        //Open child table when user clicks the image
                        $img.click(function () {
                            $('#LibrarySkippingContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'Mã đơn:  ' + SkippingDetailData.record.BorrowingID,
                                        actions: {
                                            listAction: '@Url.Action("GetSkippingDetailList","SkippingDetail")?ID=' + SkippingDetailData.record.ID,
                                            deleteAction: '@Url.Action("DeleteSkippingDetail","SkippingDetail")',
                                            updateAction: '@Url.Action("UpdateSkippingDetail", "SkippingDetail")',
                                            createAction: '@Url.Action("AddSkippingDetail", "SkippingDetail")'
                                        },
                                        fields: {
                                            ID: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                type: 'hidden',
                                                defaultValue: SkippingDetailData.record.ID
                                            },
                                            SkippingID: {
                                                title: 'Mã hoãn trả sách',
                                             },
                                            BookID: {
                                                title: 'Sách',
                                                options: '@Url.Action("BookOptions","Book")'
                                            },
                                            Quantity:{
                                                title: 'Số lượng'
                                            },                                         
                                        }
                                    },
                                     function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                        });
                        //Return image to show on the person row
                        return $img;
                    }
                },
                BorrowingID: {
                    title: 'Mã mượn sách',
                    edit: false                    
                },
                EmployerID: {
                    title: 'Nhân viên',
                    create: false,
                    edit: false,
                    options: '@Url.Action("EmployeeOptions","Employee")'
                },
                Reason:{
                    title: 'Lý do',
                    type: 'textarea'
                },
                SkippedDate: {
                    title: 'Ngày bị hoãn',
                    type: 'date',
                    displayFormat: 'yy-mm-dd'
                },
                CheckAgreed: {
                    title: 'Kiểm tra (Đồng ý/Không đồng ý)',
                    type: 'checkbox',
                    values: { 'false': 'Không đồng ý', 'true': 'Đồng ý' },
                    defaultValue: 'false'
                },               
            },
            //validate cac field trong bang Libraty_Books
            formCreated: function (event, data) {
                data.form.find('input[name="BorrowingID"]').addClass('validate[required,custom[number]]');              
                data.form.find('input[name="Reason"]').addClass('validate[required]');
                data.form.find('input[name="SkippedDate"]').addClass('validate[required,custom[date]]');              
                data.form.validationEngine();
            },
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            },
        });
        //Load person list from server
        $('#LoadRecordsButton').click(function (e) {
            e.preventDefault();
            $('#LibrarySkippingContainer').jtable('load', {
                borrowingID: $('#borrowingID').val(),              
                employerID: $('#empID').val(),
            });
        });
        //Load all records when page is first shown
        $('#LoadRecordsButton').click();
    });
</script>
</div>
<div style="clear: both"></div>